//package com.nlscan.base.publico.util;
//
//import com.nlscan.qdkit.ui.publico.R;
//import com.nlscan.common.base.App;
//import com.qing.mvpart.mvp.BasePresenter;
//import com.quvii.qvlib.util.LogUtil;
//import com.quvii.qvlib.util.QvNetUtil;
//import com.quvii.qvlib.util.QvToastUtil;
//
//import io.reactivex.Observer;
//import io.reactivex.disposables.CompositeDisposable;
//import io.reactivex.disposables.Disposable;
//
///**
// * 自定义订阅者
// *
// * @param <T>
// */
//public class MyObserver<T> implements Observer<T> {
//    private CompositeDisposable compositeDisposable;
//    private BasePresenter basePresenter;
//    private boolean checkNet = false;
//    private String failInfo = null;
//    private String successInfo = null;
//
//    public MyObserver() {
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable) {
//        this.compositeDisposable = compositeDisposable;
//    }
//
//    public MyObserver(BasePresenter basePresenter) {
//        this.basePresenter = basePresenter;
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, BasePresenter basePresenter) {
//        this.compositeDisposable = compositeDisposable;
//        this.basePresenter = basePresenter;
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, boolean checkNet) {
//        this.compositeDisposable = compositeDisposable;
//        this.checkNet = checkNet;
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, BasePresenter basePresenter, boolean checkNet) {
//        this.compositeDisposable = compositeDisposable;
//        this.basePresenter = basePresenter;
//        this.checkNet = checkNet;
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, BasePresenter basePresenter, boolean checkNet, String failInfo) {
//        this.compositeDisposable = compositeDisposable;
//        this.basePresenter = basePresenter;
//        this.checkNet = checkNet;
//        this.failInfo = failInfo;
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, BasePresenter basePresenter, boolean checkNet, boolean isShowLoading) {
//        this.compositeDisposable = compositeDisposable;
//        this.basePresenter = basePresenter;
//        this.checkNet = checkNet;
//
//        if (basePresenter != null && isShowLoading) {
//            basePresenter.getV().showLoading();
//        }
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, BasePresenter basePresenter, boolean checkNet, boolean isShowLoading, String failInfo) {
//        this.compositeDisposable = compositeDisposable;
//        this.basePresenter = basePresenter;
//        this.checkNet = checkNet;
//        this.failInfo = failInfo;
//
//        if (basePresenter != null && isShowLoading) {
//            basePresenter.getV().showLoading();
//        }
//    }
//
//    public MyObserver(CompositeDisposable compositeDisposable, BasePresenter basePresenter, boolean checkNet, boolean isShowLoading, String failInfo, String successInfo) {
//        this.compositeDisposable = compositeDisposable;
//        this.basePresenter = basePresenter;
//        this.checkNet = checkNet;
//        this.failInfo = failInfo;
//        this.successInfo = successInfo;
//
//        if (basePresenter != null && isShowLoading) {
//            basePresenter.getV().showLoading();
//        }
//    }
//
//    @Override
//    public void onSubscribe(Disposable d) {
//        LogUtil.d("MyObserver: onSubscribe");
//        //接下来可以检查网络连接等操作
//        if (checkNet && !QvNetUtil.isNetworkConnected(App.getInstance())) {
//            QvToastUtil.showL(R.string.key_general_network_unavailable);
//            onNetworkUnavailable();
//            // 一定好主动调用下面这一句
//            d.dispose();
//            onComplete();
//            return;
//        }
//        if (compositeDisposable != null) {
//            compositeDisposable.add(d);
//        }
//    }
//
//    public void onNetworkUnavailable() {
//
//    }
//
//    @Override
//    public void onNext(T t) {
//        LogUtil.i("MyObserver: onNext");
//        if (basePresenter == null || basePresenter.isViewAttached()) {
//            onMyNext(t);
//        }
//    }
//

//
////    @Override
////    public void onError(Throwable e) {
////        LogUtil.d("MyObserver: onError");
////        LogUtil.printStackTrace(e);
////        if (basePresenter == null || basePresenter.isViewAttached()) {
////            if (e instanceof EmitterUtils.ExtError) {
////                onMyError((EmitterUtils.ExtError) e);
////            } else {
////                onMyError(e);
////            }
////        }
////    }
//
//    @Override
//    public void onComplete() {
//        LogUtil.i("MyObserver: onComplete");
//        if (basePresenter == null || basePresenter.isViewAttached()) {
//            onMyComplete();
//        }
//    }
//
//    /**
//     * view绑定后才调用
//     */
//    public void onMyNext(T t) {
//        if (basePresenter != null && basePresenter.isViewAttached()) {
//            basePresenter.getV().hideLoading();
//            if (successInfo != null) {
//                basePresenter.getV().showMessage(successInfo);
//            }
//        }
//    }
//
////    public void onMyError(Throwable e) {
////        if (basePresenter != null && basePresenter.isViewAttached()) {
////            basePresenter.getV().hideLoading();
////            if (e.getMessage() == null && e instanceof TimeoutException) {
////                failInfo = App.getInstance().getString(R.string.general_timeout);
////            }
////
////            if (failInfo == null) {
////                String code = QvSdkErrorUtil.getSdkResult(e);
////                if (code != null) {
////                    basePresenter.getV().showMessage(code);
////                } else {
////                    basePresenter.getV().showMessage(e.getMessage());
////                }
////            } else {
////                basePresenter.getV().showMessage(failInfo);
////            }
////        }
////    }
////
////    public void onMyError(EmitterUtils.ExtError error) {
////        if (basePresenter != null && basePresenter.isViewAttached()) {
////            basePresenter.getV().hideLoading();
////            basePresenter.getV().showMessage(BasePresenterUtil.getShowMsg(basePresenter.getV().getActivity(), error));
////        }
////    }
//
//    public void onMyComplete() {
//        if (basePresenter != null && basePresenter.isViewAttached()) {
//            basePresenter.getV().hideLoading();
//        }
//    }
//}